<template>
  <div class="Register">
    <p>注册</p>
<van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="用户名"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">注册</van-button>
  </div>
</van-form>
  </div>
</template>

<script>
import service from '../../../utils/service';
export default {
    data() {
    return {
      username: '',
      password: '',
    };
    },
     methods: {
    onSubmit(values) {
        service({
            url:"http://118.178.238.19:3001/api/user/dofinishregister",
            method:"post",
            data: {'tel':this.username,'password':this.password}
        }).then((res)=>{
          if(res.data.code == 200) {
              alert('注册成功')
              this.$router.push('/Login')
          } else if(res.data.code == 400) {
              alert('该用户已注册')
          } else {
              alert('注册失败')
          }
      })
    },
  },
};
</script>

<style scoped>
    .Register{
        width: 100%;
        text-align: center;
    }
    .Register>p{
        width: 100px;
        height: 50px;
        background-color: rgba(218, 202, 202, 0.265);
        border-radius: 10px;
        text-align: center;
        line-height: 50px;
        font-size: 20px;
        /* font-weight: 700; */
        margin: 30px auto;
    }
</style>